﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pub
{
    public static class CPicture
    {
        public static void ImageFormatter(string sourcePath, string distationPath, string format)
        {
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(sourcePath);
            try
            {

                switch (format.ToLower())
                {

                    case "bmp":
                        bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Bmp);
                        break;
                    case "emf":
                        bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Emf);
                        break;
                    case "gif":
                        bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Gif);
                        break;
                    case "ico":
                        bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Icon);
                        break;
                    case "jpg":
                        bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;
                    case "png":
                        bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Png);
                        break;
                    case "tif":
                        bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Tiff);
                        break;
                    case "wmf":
                        bitmap.Save(distationPath, System.Drawing.Imaging.ImageFormat.Wmf);
                        break;
                    default: throw new Exception("无法转换此格式！");
                }
                bitmap.Dispose();
                bitmap = null;
            }
            catch (System.Exception ex)
            {
                bitmap.Dispose();
                bitmap = null;
                CDebug.SendError(ex.ToString());
                CDebug.Send("转换格式出错", ex);
            }

        }
    }
}
